package com.company;

/**
 * @date : 2022-01-10 下午11:26
 * mysql 索引创建
 * 索引创建和删除的方式
 * 最多创建64索引+主键
 */

public class P015_MySQLCreateIndex {
    public static void main(String[] args) {
        // System.out.println(createIndex2());
        System.out.println(deleteIndex());
    }

    public static String createIndex2() {
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < 63; i++) {
            ans.append("CREATE INDEX idx_name_").append(i).append(" ON test (name_").append(i).append(");\n");
        }
        return ans.toString();
    }

    public static String createIndex() {
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < 63; i++) {
            ans.append("ALTER TABLE test ADD INDEX idx_name_").append(i).append(" (name_").append(i).append(");\n");
        }
        return ans.toString();
    }

    public static String deleteIndex2() {
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < 63; i++) {
            ans.append("DROP INDEX idx_name_").append(i).append(" ON test;\n");
        }
        return ans.toString();
    }

    public static String deleteIndex() {
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < 63; i++) {
            ans.append("ALTER TABLE test DROP INDEX idx_name_").append(i).append(";\n");
        }
        return ans.toString();
    }
}
